﻿using AutoFrameUI;
using CommonTool;
using Motions;
using Station;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO.Ports;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using Tool;

namespace AutoMachine
{
    public partial class Frm_Main : Form
    {

        public Frm_Main()
        {
            InitializeComponent();

            #region 任务栏显示
            //最大化显示任务栏
            this.StartPosition = FormStartPosition.Manual;

            //最大化显示任务栏
            this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
            //最大化显示任务栏
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

            #endregion
        }

        #region 窗体对象实例
        /// <summary>
        /// 窗体对象实例
        /// </summary>
        private static Frm_Main _instance;
        public static Frm_Main Instance
        {
            get
            {
                if (_instance == null || _instance.IsDisposed)
                    _instance = new Frm_Main();
                return _instance;
            }
        }
        #endregion

        #region  实例化

        /// <summary>
        /// 监控线程
        /// </summary>
        private Thread th_update;
        bool Frm_mainFlag = false;

        Tool.AutoResize FormResize = new AutoResize();

        Init init = new Init();
        
        /// <summary>
        /// 按钮名称绑定窗口
        /// </summary>
        Dictionary<RoundButton, Form> m_dicForm = new Dictionary<RoundButton, Form>();

        /// <summary>
        /// 当前显示窗口,按钮
        /// </summary>
        Form m_currentForm = null;

        RoundButton m_currentButton = null;

        #endregion

        private void Frm_Main_Load(object sender, EventArgs e)
        {

            //项目名称
            this.RoundButton_Machine.Text = SystemCfg.Param["DeviceName"].Value.ToString();

            //开启 启动 停止 暂停 硬件监控线程
            th_update = new Thread(IO);
            th_update.IsBackground = true;
            th_update.Start();

            //GlobalVar.LCRTCP.Connect();
            //GlobalVar.LCRTCP.DataReceivedEvent += LCRTCP_DataReceivedEvent;
            //GlobalVar.CCDTCP.Connect();
            //GlobalVar.CCDTCP.DataReceivedEvent += CCDTCP_DataReceivedEvent;
            //蜂鸣器线程
            //th_update1 = new Thread(Axis);
            //th_update1.IsBackground = true;
            //th_update1.Start();

            // 关联页面和站位
            m_dicForm.Add(RoundButton_Auto, new Frm_Auto());//主画面

            m_dicForm.Add(RoundButton_Manual, new Frm_Manual());//手动画面

            m_dicForm.Add(RoundButton_Vision, new Frm_Vision());//视觉画面

            m_dicForm.Add(RoundButton_Alarm, new Frm_Alarm());//报警画面

            m_dicForm.Add(RoundButton_Chart, new Frm_Chart());//报表画面

            m_dicForm.Add(RoundButton_Set, new Frm_Set());//报表画面

            try
            {
                //初始化页面属性
                //初始化页面属性
                foreach (KeyValuePair<RoundButton, Form> kp in m_dicForm)
                {
                    kp.Value.TopLevel = false;
                    kp.Value.Parent = this.MainPanel;
                    kp.Value.Dock = DockStyle.Fill;
                    kp.Value.FormBorderStyle = FormBorderStyle.None;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            //报警画面，为了实现委托函数 先加载报警画面再切换成自动画面
            SwitchWnd(RoundButton_Alarm);

            Thread.Sleep(100);

            //自动画面
            SwitchWnd(RoundButton_Auto);

            // FormResize.SetAutoResize(this);//窗体缩放实例化

            //设备运行模式
            Device.OperationModeChangeEvent += OperationModeChange;

            //设备登录等级
            Device.OperationLevelChangeEvent += OperationLevelChange;

            //设备状态模式
            Device.StateModeChangeEvent += StateModeChange;

            //系统时间显示靠右
            statusStrip1.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
            toolStripStatusLabel4.Alignment = ToolStripItemAlignment.Right;

            //  MotionMgr.GetInstance().ALLSeverOn();//所有轴上使能

            //最初的状态
            OperationLevelChange(Device.OperationLevel.NoLevel);

            OperationModeChange(Device.OperationMode.NormalMode);

            StateModeChange(Device.STATEMode.STOP);
            StartStation();
            Frm_mainFlag = true;
        }

        private void Frm_Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("请确认是否退出系统？", "退出系统", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.OK)
                {
                  
                  
                    GlobalVar.CCDTCP.Close();
                    this.Dispose();

                    System.Environment.Exit(1);//强制关闭

                    Thread.Sleep(1000);

                    e.Cancel = false;
                }
                else
                {
                    e.Cancel = true; // 取消关闭事件
                }
            }
            catch
            {
                Application.Exit();
            }
        }


        #region 界面切换
        /// <summary>
        /// 登录点击的界面
        /// </summary>
        /// <param name="frm"></param>
        /// <param name="btn"></param>
        /// <param name="bPopBox"></param>
        /// <returns></returns>
        public void SwitchWnd(RoundButton btn)
        {
            if (m_currentButton != btn && m_dicForm.ContainsKey(btn))
            {
                m_currentButton = btn;
                if (m_currentForm != null)
                    m_currentForm.Hide();
                if (m_currentForm != m_dicForm[btn])
                {
                    m_currentForm = m_dicForm[btn];
                    m_currentForm.Show();
                }
            }
        }

        #endregion

        #region 事件刷新

        /// <summary>
        /// 串口触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                if (!Frm_SerialPort.Instance.serialPort.IsOpen)
                {
                    MessageBox.Show("串口未打开");
                    return;
                }
                string receiveStr = Frm_SerialPort.Instance.serialPort.ReadExisting();//收到的内容
                if (receiveStr != "")
                {

                }
            }
            catch (Exception ex)
            {
                LogView.GetInstance().ShowLogSave(LogView.LogType.Error, ex.Message);//保存Log
                MessageBox.Show(ex.Message);
            }
        }
        void ClientDataRecevied(string str)
        {
            string[] str1 = str.Split(',');
            if (str1[0] == "M0"&& str1.Length>1)
            {

                GlobalVar.LenList.Add(str1[1]);
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "网口接收:"+str);//保存Log
            }
            else
            {
                GlobalVar.LenList.Add("0");
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "网口接收:"+ str);//保存Log
            }

        }

        /// <summary>
        /// 视觉数据接收
        /// </summary>
        /// <param name="str"></param>
        void CCDTCP_DataReceivedEvent(string str)
        {
            byte[] bytes = Encoding.ASCII.GetBytes(str);
            if (bytes[0]==0x01&& bytes[1] == 0x01 && bytes[2] == 0x01)
            {
                for (int i = 0; i < 8; i++)
                {
                    GlobalVar.GetDI[i]=0!= (int.Parse(bytes[3].ToString()) & (1 << (i)));
                }
            }
            //GlobalVar.DataCCD.Add(str);
            



        }
        /// <summary>
        /// 视觉数据接收
        /// </summary>
        /// <param name="str"></param>
        void LCRTCP_DataReceivedEvent(string str)
        {

            string[] str1 = str.Split(',');
            if (str1.Length==3)
            {
                string CPstr = str1[0];
                string RPstr = str1[1];
                CPstr = CPstr.Split('E')[0];
                RPstr = RPstr.Split('E')[0];
                decimal CP= decimal.Parse(CPstr)*10;
                decimal RP = decimal.Parse(RPstr) /10;
                //LogView.GetInstance().ShowLog(LogView.LogType.Oper, "网口接收:" + $"CP={CP}pF,RP={RP}");
            }

            //GlobalVar.DataCCD.Add(str);
            


        }
        #region 设备状态变化
        private void StateModeChange(Device.STATEMode StateMode)
        {
            if (StateMode == Device.STATEMode.RUN)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备运行中");
                CtrDisplay.ShowText(toolStripStatusLabel6, "设备运行中", Color.Green, Color.Empty);
                GreenLight();
            }
            else if (StateMode == Device.STATEMode.PAUSE)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备暂停中");
                CtrDisplay.ShowText(toolStripStatusLabel6, "设备暂停中", Color.Yellow, Color.Empty);
                YellowLight();
            }
            else if (StateMode == Device.STATEMode.STOP)
            {
                //设备状态变化时
                // Task.Factory.StartNew(() => StopStation());
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备停止中");
                CtrDisplay.ShowText(toolStripStatusLabel6, "设备停止中", Color.Red, Color.Empty);
                RedLight();
            }
            else if (StateMode == Device.STATEMode.EMG)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备急停中");
                CtrDisplay.ShowText(toolStripStatusLabel6, "设备急停中", Color.Red, Color.Empty);
                RedLight();
            }
            else if (StateMode == Device.STATEMode.ALARM)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备报警中");
                CtrDisplay.ShowText(toolStripStatusLabel6, "设备报警中", Color.Red, Color.Empty);
                RedLight();
            }
            else if (StateMode == Device.STATEMode.Reseted)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备复位完成");
                CtrDisplay.ShowText(toolStripStatusLabel6, "设备复位完成", Color.Green, Color.Empty);
                GreenLight();
            }
            else if (StateMode == Device.STATEMode.Resetting)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备正在复位");
                CtrDisplay.ShowText(toolStripStatusLabel6, "设备正在复位", Color.Green, Color.Empty);
                YellowLight();
            }
        }

        /// <summary>
        /// 权限管理
        /// </summary>
        /// <param name="OperLevel"></param>
        private void OperationLevelChange(Device.OperationLevel OperLevel)
        {
            if (OperLevel == Device.OperationLevel.NoLevel)
            {
                CtrDisplay.ShowText(toolStripStatusLabel3, "无登录");
            }
            if (OperLevel == Device.OperationLevel.Admin)
            {
                CtrDisplay.ShowText(toolStripStatusLabel3, "管理员");
            }
            if (OperLevel == Device.OperationLevel.Developer)
            {
                CtrDisplay.ShowText(toolStripStatusLabel3, "开发人员");
            }
            if (OperLevel == Device.OperationLevel.Operator)
            {
                CtrDisplay.ShowText(toolStripStatusLabel3, "操作员");
            }

        }

        /// <summary>
        /// 运行模式
        /// </summary>
        /// <param name="OperMode"></param>
        private void OperationModeChange(Device.OperationMode OperMode)
        {
            if (OperMode == Device.OperationMode.NormalMode)
            {
                CtrDisplay.ShowText(toolStripStatusLabel8, "正常运行模式", Color.Green, Color.Empty);
            }
            if (OperMode == Device.OperationMode.DryRunMode)
            {
                CtrDisplay.ShowText(toolStripStatusLabel8, "空跑运行模式", Color.Red, Color.Empty);
            }
        }

        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            string s = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            this.toolStripStatusLabel4.Text = "系统时间:" + " " + s;
            if (GlobalVar.CCDTCP.IsRunning == true)
            {
                if (GlobalVar.CCDTCP.socketclient!=null)
                {
                    ModeBusSend modeBusSend = new ModeBusSend();
                    GlobalVar.CCDTCP.Send(modeBusSend.GetDI);
                }
                
            }
            if (!GlobalVar.CCDTCP.IsRunning&& GlobalVar.CCDTCP.socketclient == null)
            {
                GlobalVar.CCDTCP.Connect();
            }

            timer1.Enabled = true;
            //定时删除文件夹里的图片

            //    Tool.WriteLog.DeleteFile(SettingConfig.日志存储路径, SettingConfig.图片保存天数);
        }

        #endregion

        #region 三色灯

        ///// <summary>
        /// 红灯亮 黄灯灭 绿灯灭
        /// </summary>
        private void RedLight()
        {
            //MotionMgr.GetInstance().WriteOut("三色灯红1", true);//输出红灯
            //MotionMgr.GetInstance().WriteOut("三色灯黄1", false);//输出黄灯
            //MotionMgr.GetInstance().WriteOut("三色灯绿1", false);//输出绿灯
            //MotionMgr.GetInstance().WriteOut("三色灯红2", true);//输出红灯
            //MotionMgr.GetInstance().WriteOut("三色灯黄2", false);//输出黄灯
            //MotionMgr.GetInstance().WriteOut("三色灯绿2", false);//输出绿灯
        }

        /// <summary>
        /// 黄灯亮 红灯灭 绿灯灭
        /// </summary>
        private void YellowLight()
        {
            //MotionMgr.GetInstance().WriteOut("三色灯红1", false);//输出红灯
            //MotionMgr.GetInstance().WriteOut("三色灯黄1", true);//输出黄灯
            //MotionMgr.GetInstance().WriteOut("三色灯绿1", false);//输出绿灯
            //MotionMgr.GetInstance().WriteOut("三色灯红2", false);//输出红灯
            //MotionMgr.GetInstance().WriteOut("三色灯黄2", true);//输出黄灯
            //MotionMgr.GetInstance().WriteOut("三色灯绿2", false);//输出绿灯
        }

        /// <summary>
        /// 绿灯亮 黄灯灭 红灯灭 
        /// </summary>
        private void GreenLight()
        {
            //MotionMgr.GetInstance().WriteOut("三色灯红1", false);//输出红灯
            //MotionMgr.GetInstance().WriteOut("三色灯黄1", false);//输出黄灯
            //MotionMgr.GetInstance().WriteOut("三色灯绿1", true);//输出绿灯
            //MotionMgr.GetInstance().WriteOut("三色灯红2", false);//输出红灯
            //MotionMgr.GetInstance().WriteOut("三色灯黄2", false);//输出黄灯
            //MotionMgr.GetInstance().WriteOut("三色灯绿2", true);//输出绿灯 
        }

        /// <summary>
        /// 蜂鸣器
        /// </summary>
        /// <param name="OnOff"></param>
        public static void Buzzer(bool OnOff)
        {
            bool bit;

            if (GlobalVar.Buzzer == false)
            {
                bit = OnOff;
            }
            else
            {
                bit = false;
            }
            MotionMgr.GetInstance().WriteOut("蜂鸣器1", bit);//输出红灯
            //MotionMgr.GetInstance().WriteOut("蜂鸣器2", bit);//输出红灯
        }

        #endregion

        #region 启动 停止 复位 暂停

        //复位按钮
        private void RoundButton_Reset_Click_1(object sender, EventArgs e)
        {
            //Task.Factory.StartNew(() => Home());
        }

        //启动按钮
        private void RoundButton_Start_Click_1(object sender, EventArgs e)
        {
            Start();
        }

        //暂停按钮
        private void RoundButton_Pause_Click_1(object sender, EventArgs e)
        {
            //Pause();
        }

        //停止按钮
        private void RoundButton_Stop_Click_1(object sender, EventArgs e)
        {
            //DialogResult result = MessageBox.Show("请确认是否停止设备!!!\n\r设备停止后需要重新复位", "设备停止", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            //if (result == DialogResult.OK)
            //{
            //    Stop();
            //}

        }

        /// <summary>
        /// 启动站位
        /// </summary>
        private void StartStation()
        {
            //foreach (StationBase item in SystemCfg.listStation)
            //{
            //    item.StartRun();
            //}
            SystemCfg.listStation[0].StartRun();
        }

        /// <summary>
        /// 停止站位
        /// </summary>
        private void StopStation()
        {
            init.StopRun();
            foreach (StationBase item in SystemCfg.listStation)
            {
                item.StopRun();
            }
        }

        /// <summary>
        /// 启动
        /// </summary>
        private void Start1()
        {
            if (!MotionMgr.GetInstance().ReadIn("停止1") ||!MotionMgr.GetInstance().ReadIn("停止"))
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Error ,"设备暂停按钮按下,请先解除暂停");
                //MessageBox.Show("设备正在复位");
                return;
            }
            if (!MotionMgr.GetInstance().ReadIn("急停1") || !MotionMgr.GetInstance().ReadIn("急停"))
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Error, "设备暂停按钮按下,请先解除暂停");
                //MessageBox.Show("设备正在复位");
                return;
            }
            if ((!MotionMgr.GetInstance().ReadIn("前门磁1") || !MotionMgr.GetInstance().ReadIn("后门磁1") || !MotionMgr.GetInstance().ReadIn("左门磁1") || !MotionMgr.GetInstance().ReadIn("前门磁") || !MotionMgr.GetInstance().ReadIn("后门磁") || !MotionMgr.GetInstance().ReadIn("右门磁")) && GlobalVar.Door == false)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Error, "设备门已开,请先关门");
                //MessageBox.Show("设备正在复位");
                return;
            }
            if (Device.StateMode == Device.STATEMode.Resetting)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备正在复位");
                MessageBox.Show("设备正在复位");
                return;
            }
            if (Device.StateMode == Device.STATEMode.STOP || !SystemMgr.GetInstance().GetSysBit(SysBit.HpmeOKAll))
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备请先复位");
                MessageBox.Show("设备请先复位");
                return;
            }
            if (Device.StateMode == Device.STATEMode.PAUSE)//暂停中 继续运行
            {
                Device.ChangeStateMode(Device.STATEMode.RUN);
            }
            if (Device.StateMode == Device.STATEMode.Reseted)//复位完成 
            {
                //StartStation();
                Device.ChangeStateMode(Device.STATEMode.RUN);
            }
            if (Device.StateMode == Device.STATEMode.ALARM)//暂停中 继续运行
            {
                Device.ChangeStateMode(Device.STATEMode.RUN);
            }
        }

        private void Start()
        {
            if (Device.StateMode == Device.STATEMode.RUN)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Oper, "设备正在运行中,请勿重复按压");
                return;
            }
            if (!MotionMgr.GetInstance().ReadIn("安全光栅"))
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Error, "设备光栅信号异常,请先解除异常");
                //MessageBox.Show("设备正在复位");
                return;
            }
            Device.ChangeStateMode(Device.STATEMode.RUN);
        }
        /// <summary>
        /// 暂停
        /// </summary>
        private void Pause()
        {
            if (Device.StateMode == Device.STATEMode.RUN)//运行中 转暂停
            {
                Device.ChangeStateMode(Device.STATEMode.PAUSE);
            }
            else
            {
                return;
            }
        }

        /// <summary>
        /// 停止
        /// </summary>
        private void Stop()
        {
            if (Device.StateMode == Device.STATEMode.Resetting || Device.StateMode == Device.STATEMode.Reseted)
            {
                MotionMgr.GetInstance().ALLEmgAxis();
                init.StopRun();
                Device.ChangeStateMode(Device.STATEMode.STOP);
            }
            if (Device.StateMode == Device.STATEMode.RUN || Device.StateMode == Device.STATEMode.PAUSE)//运行中 暂停中 转停止
            {
                StopStation();
                Device.ChangeStateMode(Device.STATEMode.STOP);
            }
        }

        /// <summary>
        /// 复位
        /// </summary>
        private void Home()
        {

            if (Device.StateMode == Device.STATEMode.RUN || Device.StateMode == Device.STATEMode.PAUSE)
            {
                LogView.GetInstance().ShowLog(LogView.LogType.Error, "设备正在运动中");
                return;
            }
            if (Device.StateMode == Device.STATEMode.STOP || Device.StateMode == Device.STATEMode.EMG)//停止中 急停中
            {
                init.StartRun();
            }
        }

        /// <summary>
        /// 急停
        /// </summary>
        private void Emg()
        {
            foreach (StationBase item in SystemCfg.listStation)
            {
                item.EmgWork();
            }
            MotionMgr.GetInstance().ALLSeverOff();
            MotionMgr.GetInstance().ALLEmgAxis();
            Device.ChangeStateMode(Device.STATEMode.EMG);
            StopStation();
            SystemMgr.GetInstance().WriteSysBit(SysBit.HpmeOKAll, false);
        }

        /// <summary>
        /// 报警
        /// </summary>
        private void Alarm()
        {
            //轴减速停止
            MotionMgr.GetInstance().ALLEmgAxis();
            Device.ChangeStateMode(Device.STATEMode.ALARM);
        }

        /// <summary>
        /// 启动 停止 硬件触发
        /// </summary>
        private void IO()
        {
            //复位延时
            int Resttime = 0;
            //启动延时
            int Starttime = 0;
            int UpTime1 = 0;
            int UpTime2 = 0;
            int DownTime1 = 0;
            int DownTime2 = 0;

            while (true)
            {
                try
                {
                    //if (MotionMgr.GetInstance().Card.CardIniOK)
                    //{
                        //硬件 启动 停止
                        if (Convert.ToBoolean(SystemCfg.Param["HardWare"].Value.ToString()) == true)
                        {
                        if (Device.StateMode != Device.STATEMode.RUN)
                        {
                            if (!MotionMgr.GetInstance().ReadIn("启动2"))
                            {
                                Starttime++;
                                //延时启动

                                if (Starttime > 10)
                                {
                                    Starttime = 0;
                                    Start();
                                }
                            }
                            else
                            {
                                Starttime = 0;
                            }
                        }
                           
                        if (!MotionMgr.GetInstance().ReadIn("安全光栅"))
                        {
                            Pause();
                        }
                         
                        }


                    //}


                    Thread.Sleep(3);
                }
                catch (Exception ex)
                {

                    MessageBox.Show(ex.Message);
                }
            }



        }

        private void Axis()
        {

            try
            {
                while (true)
                {
                    if (MotionMgr.GetInstance().Card.CardIniOK)
                    {
                        if (GlobalVar.Buzzer == true && GlobalVar.BuzzerScreen == false)
                        {
                            MotionMgr.GetInstance().WriteOut("蜂鸣器1", true);//输出红灯
                            //MotionMgr.GetInstance().WriteOut("蜂鸣器2", true);//输出红灯
                        }
                        else
                        {
                            MotionMgr.GetInstance().WriteOut("蜂鸣器1", false);//输出红灯
                            MotionMgr.GetInstance().WriteOut("蜂鸣器2", false);//输出红灯
                        }
                        if (Device.StateMode == Device.STATEMode.RUN)
                        {
                            if (MotionMgr.GetInstance().AxisAlarm() == true)
                            {
                                Alarm();
                            }
                            if (MotionMgr.GetInstance().AxisPosLimit() == true)
                            {
                                Alarm();
                            }
                            if (MotionMgr.GetInstance().AxisNegLimit() == true)
                            {
                                Alarm();
                            }

                        }
                    }

                    Thread.Sleep(100);
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

        }


        #endregion

        #region 按钮画面

        //主画面
        private void RoundButton_Auto_Click(object sender, EventArgs e)
        {

            SwitchWnd(RoundButton_Auto);

        }

        //手动画面
        private void RoundButton_Manual_Click(object sender, EventArgs e)
        {
            SwitchWnd(RoundButton_Manual);
        }

        //视觉画面
        private void RoundButton_Vision_Click(object sender, EventArgs e)
        {
            SwitchWnd(RoundButton_Vision);
        }

        //报警画面
        private void RoundButton_Alarm_Click(object sender, EventArgs e)
        {
            SwitchWnd(RoundButton_Alarm);
        }

        //报表画面
        private void RoundButton_Chart_Click(object sender, EventArgs e)
        {
            SwitchWnd(RoundButton_Chart);
        }

        //设置画面
        private void RoundButton_Set_Click(object sender, EventArgs e)
        {
            SwitchWnd(RoundButton_Set);
        }



        private void RoundButton_Machine_Click(object sender, EventArgs e)
        {

            GlobalVar.CCDTCP.Connect();
        }


        //登录按钮
        private void RoundButton_Login_Click_1(object sender, EventArgs e)
        {
            Frm_Login.Instance.ShowDialog();
        }






        #endregion

    }
}
